﻿using Microsoft.Win32;
namespace UniMana.Utils.Helper
{
    public class ClsRegistryOperator
    {

        RegistryKey m_regKey = Registry.CurrentUser;

        public ClsRegistryOperator(string nstrPathKey = @"Softa_DHLA\UniversityManagement")
        {
            //RegistryKey regKey = Registry.CurrentUser;
             m_regKey = m_regKey.CreateSubKey(nstrPathKey);
        }

        public string ReadRegistry(string nstrNameKey)
        {
            string strValue = "";
            if (m_regKey.GetValue(nstrNameKey) != null)
            {
                strValue = m_regKey.GetValue(nstrNameKey).ToString();
                strValue=strValue.Decrypt();
            }
            return strValue;
        }
        public void SaveInfoRegistry(string nstrNameKey, string nstrValue)
        {
            if (nstrNameKey != "" && nstrValue!="")
            {
                nstrValue = nstrValue.Encrypt();
                m_regKey.SetValue(nstrNameKey, nstrValue);
            }
        }
        public void DelRegistry(string nstrNameKey)
        {
            try
            {
                m_regKey.DeleteValue(nstrNameKey);
            }
            catch
            {
            }
        }

        ~ClsRegistryOperator()
        {
            m_regKey.Close();
        }

    }
}
